#pragma once


#include <sstream>
#include <iostream>
#include <fstream>

class Logger
{
	static std::ostringstream oss;
	static std::ostringstream tmpOss;
	static std::ostringstream nullOss;
	static std::string logFileName;
	static bool turnedOn;

public:
	static std::ostream& getOStream()
	{
		flush();
		if(turnedOn)
		{
			return tmpOss;
		}
		else
		{
			return nullOss;
		}
	}

	static void flush()
	{
		std::string s_=tmpOss.str();
		std::cout<<s_;
		std::cout.flush();
		oss<<tmpOss.str();
		tmpOss=std::ostringstream();

		nullOss=std::ostringstream();
	}

	static std::string str()
	{
		flush();
		return oss.str();
	}

	static void saveToFile()
	{
		flush();
		std::fstream fstream( logFileName, std::fstream::out);
		std::string s_=oss.str();
		fstream<<s_;
		fstream.close();
	}

	static void setTurnedOn(bool _x)
	{
		turnedOn=_x;
	}

	class TurnOffLogger
	{
	public:
		TurnOffLogger(){setTurnedOn(false);};
		~TurnOffLogger(){setTurnedOn(true);};
	};
};


